package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Missing;
import com.ruoyi.system.service.IMissingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品归还Controller
 * 
 * @author slh
 * @date 2022-11-28
 */
@RestController
@RequestMapping("/system/missing")
public class MissingController extends BaseController
{
    @Autowired
    private IMissingService missingService;

    /**
     * 查询物品归还列表
     */
    @PreAuthorize("@ss.hasPermi('system:missing:list')")
    @GetMapping("/list")
    public TableDataInfo list(Missing missing)
    {
        startPage();
        List<Missing> list = missingService.selectMissingList(missing);
        return getDataTable(list);
    }

    /**
     * 导出物品归还列表
     */
    @PreAuthorize("@ss.hasPermi('system:missing:export')")
    @Log(title = "物品归还", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Missing missing)
    {
        List<Missing> list = missingService.selectMissingList(missing);
        ExcelUtil<Missing> util = new ExcelUtil<Missing>(Missing.class);
        util.exportExcel(response, list, "物品归还数据");
    }

    /**
     * 获取物品归还详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:missing:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(missingService.selectMissingById(id));
    }

    /**
     * 新增物品归还
     */
    @PreAuthorize("@ss.hasPermi('system:missing:add')")
    @Log(title = "物品归还", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Missing missing)
    {
        return toAjax(missingService.insertMissing(missing));
    }

    /**
     * 修改物品归还
     */
    @PreAuthorize("@ss.hasPermi('system:missing:edit')")
    @Log(title = "物品归还", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Missing missing)
    {
        return toAjax(missingService.updateMissing(missing));
    }

    /**
     * 删除物品归还
     */
    @PreAuthorize("@ss.hasPermi('system:missing:remove')")
    @Log(title = "物品归还", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(missingService.deleteMissingByIds(ids));
    }
}
